﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using ShevaEngine.Core.Interfaces;
using ShevaEngine.Core.Modules.Scenes;

namespace ShevaEngine.Core.Modules.Audio
{
    /// <summary>
    /// Sound listener.
    /// </summary>
    public class SoundListener : SceneObject, IUpdateAble
    {
        /// <summary>Audio listener.</summary>
        internal AudioListener Listener;
       
        /// <summary>
        /// Constructor.
        /// </summary>
        public SoundListener()
        {
            this.Listener = new AudioListener();            
        }

        /// <summary>
        /// Method Update().
        /// </summary>
        /// <param name="time"></param>
        public void Update(GameTime time)
        {
            this.Listener.Position = -1 * this.World.Translation;
            this.Listener.Forward = Vector3.Forward;
            this.Listener.Up = Vector3.Up;
            this.Listener.Velocity = Vector3.Zero;
        }

        public override void Transform(Matrix matrix)
        {
            base.Transform(matrix);

            this.Listener.Position = -1 * this.World.Translation;
            this.Listener.Forward = Vector3.Forward;
            this.Listener.Up = Vector3.Up;
            this.Listener.Velocity = Vector3.Zero;
        }
    }
}
